<template>
  <el-table-column align=center label="操作" width="400">
    <template v-slot="scope">
        <el-button size="small" style="border-radius:2px;" icon="Edit" type="primary" plain @click="getDeploymentDetail(scope)">YAML</el-button>
        <el-button size="small" style="border-radius:2px;" icon="Plus" type="primary" @click="handleScale(scope)">扩缩</el-button>
        <el-button size="small" style="border-radius:2px;" icon="RefreshLeft" type="primary" @click="handleConfirm(scope, '重启', restartDeployment)">重启</el-button>
        <el-button size="small" style="border-radius:2px;" icon="Delete" type="danger" @click="handleConfirm(scope, '删除', delDeployment)">删除</el-button>
    </template>
</el-table-column>
</template>

export default {
  data() {
    //扩缩容
      scaleNum: 0,
      scaleDialog: false,
      scaleDeploymentData: {
          url: common.k8sDeploymentScale,
          params: {
              deployment: '',
              namespace: '',
              scalenumber: ''
          }
      },
  }
  methods {
    //扩缩容的中间方法，用于赋值及打开弹出框
    handleScale(f) {
        this.scaleDialog = true
        this.deploymentDetail = f.row
        this.scaleNum = f.row.spec.replicas
    },
    //扩缩容deployment
    scaleDeployment() {
        this.scaleDeploymentData.params.deployment = this.deploymentDetail.metadata.name
        this.scaleDeploymentData.params.namespace = this.namespaceValue
        this.scaleDeploymentData.params.scalenumber = this.scaleNum
        httpClient.post(this.scaleDeploymentData.url, this.scaleDeploymentData.params)
        .then(res => {
            this.$message.success({
            message: res.msg
            })
        })
        .catch(res => {
            this.$message.error({
            message: res.msg
            })
        })
        //更新后重新获取列表
        this.getDeployments()
        //关闭弹出框
        this.scaleDialog = false
    },
  }

}